//
//  HMStatusOriginalView.swift
//  微博
//
//  Created by 郭鉴增 on 2016/12/10.
//  Copyright © 2016年 郭鉴增. All rights reserved.
//

import UIKit
//原创微博视图
class HMStatusOriginalView: UIView {

    //所需要的视图模型(viewModel)
    var statusViewModel: HMStatusViewModel? {
        didSet {
            if let imageUrl = statusViewModel?.status?.user?.profile_image_url {
                userImageView.sd_setImage(with: URL(string: imageUrl), placeholderImage: UIImage(named: "avatar_default_big"))
            }
            screenNameLabel.text = statusViewModel?.status?.user?.screen_name
            contentLabel.text = statusViewModel?.status?.text
            
            mbrankImageView.image = statusViewModel?.mbrankImage
            
            verifiedTypeImageView.image = statusViewModel?.verifiedTypeImage
        }
    }
    
    //MARK: - 懒加载
    //用户头像
    private lazy var userImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    //认证类型等级
    private lazy var verifiedTypeImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    //昵称
    private lazy var screenNameLabel: UILabel = {
        let label = UILabel(fontSize: 14, textColor: UIColor.darkGray)
        
        label.text = "风中一枝花"
        return label
    }()
    //会员等级
    private lazy var mbrankImageView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    //时间
    private lazy var timeLabel: UILabel = {
        let label = UILabel(fontSize: 12, textColor: UIColor.orange)
        
        label.text = "刚刚"
        return label
    }()
    //来源
    private lazy var sourceLabel: UILabel = {
        let label = UILabel(fontSize: 12, textColor: UIColor.lightGray)
        
        label.text = "来自: 星星的你"
        return label
    }()
    //微博内容
    private lazy var contentLabel: UILabel = {
        let label = UILabel(fontSize: 14, textColor: UIColor.darkGray)
        
        
        //多行显示 
        label.numberOfLines = 0
        return label
    }()
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        
        
        addSubview(userImageView)
        addSubview(verifiedTypeImageView)
        addSubview(screenNameLabel)
        addSubview(mbrankImageView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(contentLabel)
        
        userImageView.snp_makeConstraints { (make) in
            make.top.equalTo(self).offset(StatusItemMargin)
            make.leading.equalTo(self).offset(StatusItemMargin)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        verifiedTypeImageView.snp_makeConstraints { (make) in
            make.centerX.equalTo(userImageView.snp_trailing)
            make.centerY.equalTo(userImageView.snp_bottom)
        }
        screenNameLabel.snp_makeConstraints { (make) in
            make.leading.equalTo(userImageView.snp_trailing).offset(StatusItemMargin)
            make.top.equalTo(userImageView)
        }
        mbrankImageView.snp_makeConstraints { (make) in
            make.leading.equalTo(screenNameLabel.snp_trailing).offset(StatusItemMargin)
            make.top.equalTo(screenNameLabel)
        }
        timeLabel.snp_makeConstraints { (make) in
            make.bottom.equalTo(userImageView)
            make.leading.equalTo(screenNameLabel)
        }
        sourceLabel.snp_makeConstraints { (make) in
            make.leading.equalTo(timeLabel.snp_trailing).offset(StatusItemMargin)
            make.bottom.equalTo(timeLabel)
        }
        contentLabel.snp_makeConstraints { (make) in
            make.top.equalTo(userImageView.snp_bottom).offset(StatusItemMargin)
            make.leading.equalTo(userImageView)
            make.width.equalTo(ScreenWidth - 2 * StatusItemMargin)
        }
        //关键代码
        self.snp_makeConstraints { (make) in
            make.bottom.equalTo(contentLabel).offset(StatusItemMargin)
        }
    }

}









